package com.xmall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xmall.bean.bo.LogListBo;
import com.xmall.bean.table.Log;
import com.xmall.bean.table.LogExample;
import com.xmall.bean.vo.ListDataVo;
import com.xmall.mapper.LogMapper;
import com.xmall.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {

    @Autowired
    LogMapper logMapper;

    @Override
    public ListDataVo<Log> queryLogList(LogListBo logListBo) {
        PageHelper.startPage(logListBo.getPage(), logListBo.getLimit());
        LogExample logExample = new LogExample();
        logExample.setOrderByClause(logListBo.getSort() + " " + logListBo.getOrder());
        LogExample.Criteria criteria = logExample.createCriteria();
        if (logListBo.getName() != null) {
            criteria.andAdminLike("%" + logListBo.getName() + "%");
        }
        criteria.andDeletedEqualTo(false);
        List<Log> logs = logMapper.selectByExample(logExample);
        PageInfo<Log> logPageInfo = new PageInfo<>(logs);
        int total = (int) logPageInfo.getTotal();
        ListDataVo<Log> logListDataVo = new ListDataVo<>();
        logListDataVo.setItems(logs);
        logListDataVo.setTotal(total);
        return logListDataVo;
    }
}
